/*
 * ${copyright}
 */
package ${basePackage}.${model}.service;

import ${basePackage}.core.entity.Page;
import ${basePackage}.core.exceptions.BaseException;
import ${basePackage}.core.exceptions.UserInfoException;
import ${basePackage}.${model}.dao.${className}DAO;
import ${basePackage}.${model}.entity.${className};
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service("userinfoSV")
@Slf4j
public class ${className}SVImpl implements ${className}SV {

    @Autowired
    private ${className}DAO ${classNameLower}DAO;

    @Resource
    private UidGenerator uidGenerator;



<#if (pkFields?size>0)>
    /**
     * 加载一个对象${className}
     <#list pkFields as field>* @param ${field.field} ${field.notes}</#list>
     * @return ${className}
     */
    @Override
    public ${className} load(<#list pkFields as field>${field.fieldType} ${field.field}<#if field_has_next>,</#if></#list>) {
            return ${classNameLower}DAO.load(<#list pkFields as field>${field.field}<#if field_has_next>,</#if></#list>);
    }
    <#list pkFields as pkField>
    /**
     * 加载一个对象${className} 通过${pkField.field}
     * @param ${pkField.field} ${pkField.notes}
     * @return ${className}
     */
    @Override
    public ${className} loadBy${pkField.field?cap_first}(${pkField.fieldType} ${pkField.field}) {
            return ${classNameLower}DAO.loadBy${pkField.field?cap_first}(${pkField.field});
    }

    </#list>

    /**
     * 删除对象${className}
     <#list pkFields as pkField>* @param ${pkField.field} ${pkField.notes}</#list>
     * @return ${className}
     */
    @Override
    public void delete(<#list pkFields as pkField>${pkField.fieldType} ${pkField.field}<#if pkField_has_next>,</#if></#list>) {
            ${classNameLower}DAO.delete(<#list pkFields as pkField>${pkField.field}<#if pkField_has_next>,</#if></#list>);
    }

</#if>


    /**
     * 查询${className}分页
     *
     <#list pkFields as pkField>* @param ${pkField.field}  ${pkField.notes}</#list>
     * @param offset 查询开始行
     * @param limit  查询行数
     * @return List<${className}>
     */
    @Override
    public List<${className}> list(<#list pkFields as pkField>${pkField.fieldType} ${pkField.field},</#list>int offset, int limit) {
            if (offset < 0) {
            offset = 0;
            }

            if (limit < 0) {
            limit = Page.limit;
            }

            return ${classNameLower}DAO.list(<#list pkFields as pkField>${pkField.field}<#if pkField_has_next>,</#if></#list>, offset, limit);
    }

    @Override
    public int count(<#list pkFields as pkField>${pkField.fieldType} ${pkField.field}<#if pkField_has_next>,</#if></#list>) {
            return ${classNameLower}DAO.count(<#list pkFields as pkField>${pkField.field}<#if pkField_has_next>,</#if></#list>,map);
    }

<#list fields as field>

<#if field.checkDate>
    /**
     * 根据时间查询${className}列表 通过${field.field}
     * @param ${field.field} ${field.notes}
     * @return List<${className}>
     */
    @Override
    public List<${className}> listBy${field.field?cap_first}Begin(${field.fieldType} ${field.field}) {
            return ${classNameLower}DAO.listBy${field.field?cap_first}Begin(${field.field});
            }

    /**
     * 根据时间查询${className}列表 通过${field.field}
     * @param ${field.field} ${field.notes}
     * @return List<${className}>
     */
    @Override
    public List<${className}> listBy${field.field?cap_first}Begin(${field.fieldType} ${field.field},int offset,int limit) {
            return ${classNameLower}DAO.listBy${field.field?cap_first}Begin(${field.field}, offset, limit);
            }

    /**
     * 根据时间查询${className}列表 通过${field.field}
     * @param ${field.field} ${field.notes}
     * @return List<${className}>
     */
    @Override
    public List<${className}> listBy${field.field?cap_first}End(${field.fieldType} ${field.field}) {
            return ${classNameLower}DAO.listBy${field.field?cap_first}End(${field.field});
            }

    /**
     * 根据时间查询${className}列表 通过${field.field}
     * @param ${field.field} ${field.notes}
     * @return List<${className}>
     */
    @Override
    public List<${className}> listBy${field.field?cap_first}End(${field.fieldType} ${field.field},int offset,int limit) {
            if (offset < 0) {
            offset = 0;
            }
            if (limit < 0) {
            limit = Page.limit;
            }
            return ${classNameLower}DAO.listBy${field.field?cap_first}End(${field.field},offset,limit);
            }

    /**
     * 根据时间查询${className}列表 通过${field.field}
     * @param ${field.field}Begin ${field.notes}Begin
     * @param ${field.field}End ${field.notes}End
     * @return List<${className}>
     */
    @Override
    public List<${className}> listBy${field.field?cap_first}(${field.fieldType} ${field.field}Begin,${field.fieldType} ${field.field}End) {
            return ${classNameLower}DAO.listBy${field.field?cap_first}(${field.field}Begin,${field.field}End);
            }

    /**
     * 根据时间查询${className}列表 通过${field.field}
     * @param ${field.field}Begin ${field.notes}Begin
     * @param ${field.field}End ${field.notes}End
     * @return List<${className}>
     */
    @Override
    public List<${className}> listBy${field.field?cap_first}(${field.fieldType} ${field.field}Begin,${field.fieldType} ${field.field}End,int offset,int limit) {
            if (offset < 0) {
            offset = 0;
            }
            if (limit < 0) {
            limit = Page.limit;
            }
            return ${classNameLower}DAO.listBy${field.field?cap_first}(${field.field}Begin,${field.field}End, offset, limit);
            }
</#if>
</#list>



    /**
     * 保存 UserInfo
     *
     * @param userInfo 对象
     */
    @Override
    public void insert(UserInfo userInfo) {
        if (userInfo == null) throw new UserInfoException(BaseException.BaseExceptionEnum.Ilegal_Param);
        userInfoDao.insert(userInfo);
    }

    /**
     * 批量保存 UserInfo
     *
     * @param userInfos UserInfo集合
     */
    @Override
    public void batchInsert(List<UserInfo> userInfos) {
        if (userInfos == null) throw new UserInfoException(BaseException.BaseExceptionEnum.Ilegal_Param);
        userInfoDao.batchInsert(userInfos);
    }

    /**
     * 更新 UserInfo
     *
     * @param userInfo 对象
     */
    @Override
    public void update(UserInfo userInfo) {
        if (userInfo == null) throw new UserInfoException(BaseException.BaseExceptionEnum.Ilegal_Param);
        userInfoDao.update(userInfo);
    }

    /**
     * 删除 根据 id
     *
     * @param id id
     */
    @Override
    public void delete(Long id) {
        if (id == null) throw new UserInfoException(BaseException.BaseExceptionEnum.Ilegal_Param);
        userInfoDao.delete(id);
    }


    /**
     * 加载一个对象 UserInfo
     *
     * @param id id
     * @return UserInfo
     */
    @Override
    public UserInfo load(Long id) {
        if (id == null) throw new UserInfoException(BaseException.BaseExceptionEnum.Ilegal_Param);
        return userInfoDao.load(id);
    }

    /**
     * 加载一个对象 UserInfo 通过 id
     *
     * @param id id
     * @return UserInfo
     */
    @Override
    public UserInfo findById(Long id) {
        if (id == null) throw new UserInfoException(BaseException.BaseExceptionEnum.Ilegal_Param);
        return userInfoDao.findById(id);
    }

    /**
     * 查询 UserInfo 分页
     *
     * @param offset 查询开始行
     * @param limit  查询行数
     * @return List<UserInfo>
     */
    @Override
    public List<UserInfo> list(int offset, int limit) {
        if (offset < 0) {
            offset = 0;
        }

        if (limit < 0) {
            limit = Page.limit;
        }
        return userInfoDao.list(offset, limit);
    }

    @Override
    public int count() {
        return userInfoDao.count();
    }


    /**
     * @param id     id
     * @param offset 查询开始行
     * @param limit  查询行数
     * @return List<UserInfo>
     */
    @Override
    public List<UserInfo> list(Long id, int offset, int limit) {
        if (id == null) throw new UserInfoException(BaseException.BaseExceptionEnum.Ilegal_Param);

        if (offset < 0) {
            offset = 0;
        }

        if (limit < 0) {
            limit = Page.limit;
        }

        return userInfoDao.list(id, offset, limit);
    }

    @Override
    public int count(Long id) {
        if (id == null) throw new UserInfoException(BaseException.BaseExceptionEnum.Ilegal_Param);
        return userInfoDao.count(id);
    }
}
